<?php 
	function __autoload($class){
		require_once "../".$class.".php";
	}
	require_once 'adminHeader.php';
?>
	<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' onsubmit='confirmEditManager()'/>
	<table>
		<th>Choose manager to edit</th>
		<tr>
			<td><select name='allmanagers' id='allmanagers'>
			<?php 
			$dbconnect = new DBconnect();
			$dbconnect->displayAllManagers();
			?>
			</select></td></tr>
		<tr><td><input type='submit' name='edit' value='Edit Manager' /></td></tr>		
	</table>
	</form>
	<script type="text/javascript">
		function confirmEditManager(){
			$confirm = confirm("Are you sure want to edit " + document.getElementById("allmanagers").value+"?");
			return $confirm;
		}	
	</script>
	<?php 
		if(isset($_POST['edit'])){
			$manager_no = $dbconnect->selectManagerNo($_POST['allmanagers']);
			$dbconnect->printFormToEditManager($_POST['allmanagers'], $manager_no); 
		}
		
		if(isset($_POST['update'])){
			$manager = new Manager(trim($_POST['editname']), trim($_POST['editpassword']), trim($_POST['editemail']));
				$dbconnect->updateManagerInfo($manager, $manager_no);
		}
		require_once 'adminFooter.php';
	?>
